package ar.edu.caece.compiler.grammar.factories;

import ar.edu.caece.compiler.error.ErrorManager;
import ar.edu.caece.compiler.error.ParsingException;
import ar.edu.caece.compiler.grammar.AbstractTokenVisitorFactory;
import ar.edu.caece.compiler.grammar.Recognizer;
import ar.edu.caece.compiler.grammar.TokenRecognizer;
import ar.edu.caece.compiler.grammar.TokenVisitor;

import ar.edu.caece.compiler.grammar.attributes.StringAttribute;
import ar.edu.caece.compiler.grammar.nonterminals.REL4;
import ar.edu.caece.compiler.grammar.terminals.MayorAToken;

public class REL4Factory extends AbstractTokenVisitorFactory {

	private static REL4Factory INSTANCE;
	
	public static REL4Factory getInstance() {
		if(INSTANCE==null) INSTANCE = new REL4Factory();
		return INSTANCE;
	}
	
	private REL4Factory() {
		
	}
	
	@Override
	public TokenVisitor makeChainedVisitor(
			final TokenVisitor siguiente) throws Exception {
		return new MayorAToken.MayorAChainVisitor(siguiente) {
			
			@Override
			public Recognizer mayorACase(MayorAToken llamador) {
				REL4 rel4 = new REL4(llamador);
				
				rel4.addAttribute("op",new StringAttribute("MAYOR"));
				return rel4;			}
		};
	
	}
	@Override
	public TokenVisitor makeVisitor() throws Exception {
		return new MayorAToken.MayorATokenVisitor() {
			
			@Override
			public Recognizer defaultCase(TokenRecognizer llamador) throws Exception {
				ErrorManager.getInstance().manage(llamador,"REL4",new ParsingException("Error de parsing.",REL4.class,llamador));
				return null;
			}
			
			@Override
			public Recognizer mayorACase(MayorAToken llamador) {
				REL4 rel4 = new REL4(llamador);
				
				rel4.addAttribute("op",new StringAttribute("MAYOR"));
				return rel4;
			}
		};
	}
	
	
}
